// 选中的帮派列表
var gangs = new Array();

/**
 * 获取图表数据
 * @param areaId
 */
function getChartData(areaId,gangName) {
    gang = {
        "areaId": areaId,
        "gangName": gangName
    }
    if (!contains(gangs, gang)) {
        gangs.push(gang);
    }
    $.ajax({
        url: "rank/gang",
        type: "post",
        contentType: "application/json",
        data: JSON.stringify(gangs),
        success: function (result) {
            var map = result.data;
            genChart(map);
        }
    })
}

/**
 * 获取小区信息
 * @param serverName
 */
function getArea(serverName) {
    $.ajax({
        url:"area/list?serverName="+serverName,
        dataType:"json",
        success:function(result){
            // 清空子节点
            $('#areaList li').remove();
            var list = result.data;
            list.forEach(item => {
                fun = "javascript:getGangList('" + item.areaId + "');";
                var li = '<li value="' + item.areaId + '"><a href="' + fun + '">' + item.areaName + '</a></li>';
                $("#areaList").append(li);
            })
        }
    })
}

function getGangList(areaId) {
    $.ajax({
        url: "gang/cur/"+areaId,
        type: "get",
        success: function (result) {
            var list = result.data;
            $("#gangList li").remove();
            list.forEach(item => {
                // 添加节点
                fun = "javascript:getChartData('" + areaId + "','"+ item.gangName +"');";
                var li = '<li title="战力：' + item.gangAttackNum + '">' +
                    '<a href="' + fun + '">' + item.gangName + '</a>' +
                    '</li>';
                $("#gangList").append(li);
            })

        }
    })
}

function clearChart() {
    gangs.length = 0;
    genChart();
}